package com.thomasgustavo.meugood;

import java.util.ArrayList;
import java.util.List;


public abstract class StringUtils {
	public static List<String> getConteudos(String base, String token_ini, String token_fin){
		List<String> lstResult = new ArrayList<String>();
		
		String strBase = base;
		
		while( strBase.indexOf(token_ini) >= 0 ){
			
			strBase = strBase.substring(strBase.indexOf(token_ini) + token_ini.length());
			
			String strResult = strBase.substring(0, strBase.indexOf(token_fin));
			
			lstResult.add(strResult);
		}
		
		return lstResult;
	}
	
	public static String getConteudo(String base, String token_ini, String token_fin){
		List<String> str = StringUtils.getConteudos(base, token_ini, token_fin);
		if( str.isEmpty() ){
			return null;
		}
		return StringUtils.ajeitaString(str.get(0));
	}

	public static String ajeitaString(String string) {
		StringBuffer b = new StringBuffer();
		
		for( String str : getLines(string) ){
			if( b.length() > 0 ){
				b.append(" ");
			}
			b.append(str);
		}
		
		return b.toString().trim().toUpperCase();
	}
	
	public static List<String> getLines( String string ){
		String[] array = string.split("\n");
		
		ArrayList<String> lstResult = new ArrayList<String>();
		
		for( String str : array ){
			if( !str.trim().equals("") ){
				lstResult.add(str.trim());
			}
		}
		
		return lstResult;
	}
}
